#!/usr/bin/env python
# -*- coding: utf-8 -*-

import tornado.web
from utils import log
from config import conf
from controls import data_analyze_down_mysql
from utils.session_mc import BaseHandler
from utils.session_base import Guest


class MainHandler( BaseHandler ) :

    def get( self ) :
        return self.redirect( 'homepage/index.html' )


class AppQmapHandler( BaseHandler ) :

    @Guest
    def get( self, city ) :
        platform = self.ss_ua['platform']['name']
        remote_ip = self.request.remote_ip

        data_analyze_down_mysql.add_analyze_down_item({
            'platform': platform,
            'rip': remote_ip,
            'source': city,
        })

        if platform == 'Android' :
            log.i( '[QRcode]: %s from %s' % (city,platform) )
            return self.redirect( conf.url['client_android'] )
        elif platform == 'iOS' :
            log.i( '[QRcode]: %s from %s' % (city,platform) )
            return self.redirect( conf.url['client_ios'] )
        log.i( '[QRcode]: %s from %s' % (city,platform) )
        return self.redirect( conf.url['client_pc'] )


class PageNotFoundHandler( BaseHandler ) :

    def get( self ) :
        raise tornado.web.HTTPError( 503 )


